package models

import (
	"server/service/mysql"
	"time"
)

type Nurse struct {
	Id         int       `json:"id" gorm:"not null pk autoincr unique INT(11)"`
	Name       string    `json:"name" gorm:"not null index VARCHAR(20)"`
	Address    string    `json:"address" gorm:"VARCHAR(100)"`
	Age        int       `json:"age" gorm:"not null INT(11)"`
	Position   string    `json:"position" gorm:"VARCHAR(20)"`
	Specialty  string    `json:"specialty" gorm:"VARCHAR(20)"`
	Department int       `json:"department" gorm:"not null default 0 TINYINT(4)"`
	Education  int       `json:"education" gorm:"default 0 INT(11)"`
	WorkTime   int64     `json:"work_time" gorm:"default 0 comment('入职时间') BIGINT(20)"`
	Sex        int       `json:"sex" gorm:"not null default 1 comment('1男2女') INT(11)"`
	CreatedAt  time.Time `json:"created_at" gorm:"created DATETIME"`
	UpdatedAt  time.Time `json:"updated_at" gorm:"updated DATETIME"`
}

func NewNurse() *Nurse {
	return new(Nurse)
}

func (recv *Nurse) Add() (err error) {
	return mysql.NewDB().Create(recv).Error
}

func (recv *Nurse) Update() (err error) {
	return mysql.NewDB().Save(recv).Error
}

func (recv *Nurse) Del(id int) (err error) {
	return mysql.NewDB().Delete(recv, "id = ?", id).Error
}

func (recv *Nurse) GetById(id int) (err error) {
	return mysql.NewDB().First(recv, "id = ?", id).Error
}

func (recv *Nurse) GetList() (list []*Nurse, err error) {
	list = make([]*Nurse, 0)
	err = mysql.NewDB().Find(&list).Error
	return
}
